<template>
  <div class="page">
    <Navbar title="外线联报" />
    <div class="content">
      <div class="form-content">
        <el-form :model="ruleForm" label-width="100px" size="small" :rules="rules" ref="ruleForm">
          <el-form-item label="项目选择" prop="projectId">
            <el-select v-model="ruleForm.projectId">
              <el-option v-for="item in options" :key="item.id" :label="item.projectName" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="联报类型" prop="type">
            <div class="button-list f-r a-c f-w">
              <div
                v-for="item in buttonList"
                :key="item.id"
                :class="['button-item', item.id === ruleForm.type ? 'active' : '']"
                @click="ruleForm.type = item.id"
              >
                {{ item.name }}
              </div>
            </div>
          </el-form-item>
          <el-form-item label="联系人" prop="contacts">
            <el-input v-model="ruleForm.contacts" />
          </el-form-item>
          <el-form-item label="联系方式" prop="mobile">
            <el-input v-model="ruleForm.mobile" />
          </el-form-item>
          <el-form-item label="联报内容" prop="guaranty">
            <el-input v-model="ruleForm.guaranty" type="textarea" />
          </el-form-item>
          <el-form-item label="需求描述" prop="content">
            <el-input v-model="ruleForm.content" type="textarea" />
          </el-form-item>
        </el-form>
      </div>
      <el-button type="primary" style="width: 100%;margin-top: 15px" @click="onSave">确认提交</el-button>
    </div>
  </div>
</template>

<script>
import navbar from '@/mixins/navbar'
import { http_call, http_project } from '@/api'
import { Toast } from 'vant'
export default {
  name: 'Consulting',
  mixins: [navbar],
  data() {
    return {
      ruleForm: {
        projectId: '',
        type: 1,
        contacts: '',
        mobile: '',
        guaranty: '',
        content: ''
      },
      options: [
      ],
      buttonList: [
        { id: 1, name: '通水' },
        { id: 2, name: '通电' },
        { id: 3, name: '通气' },
        { id: 4, name: '通网络' }
      ],
      rules: {
        projectId: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择联报类型', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入联系方式', trigger: 'blur' }
        ],
        contacts: [
          { required: true, message: '请输入联系人', trigger: 'blur' }
        ],
        guaranty: [
          { required: true, message: '请输入联报内容', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入需求描述', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    http_project.page({
      progress: 0
    }).then(res => {
      this.options = res.data
    })
  },
  methods: {
    onSave() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // console.log(this.ruleForm);
          // return
          http_call.create({
            ...this.ruleForm
          }).then(res => {
            Toast(res.msg)
            this.ruleForm = {
              projectId: '',
              type: 1,
              contacts: '',
              mobile: '',
              guaranty: '',
              content: ''
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.page {
    width: 100vw;
    overflow: hidden;
    .el-select,
    .el-input {
        width: 100%;
    }
    .content {
        .form-content {
            width: 100%;
            background: #FFFFFF;
            border-radius: 10px;
            padding: 27px 30px 27px 0;
        }
    }
    .button-list {
        .button-item {
            margin-right: 13px;
            width: 60px;
            height: 26px;
            border: 1px solid #2F86FD;
            border-radius: 12px;
            line-height: 24px;
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #2F86FD;
            text-align: center;
            margin-bottom: 16px;
        }
        .button-item.active {
            background: #2F86FD;
            color: #fff
        }
    }
}
</style>
